package com.aaa.controller;

import com.aaa.entity.UmsAdmin;
import com.aaa.jwt.RestResponse;
import com.aaa.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@Slf4j
@RestController
@CrossOrigin
@Controller
@RequestMapping("/mail")
public class Mailcontroller {
    @Autowired
    private MailService mailService;

    @RequestMapping(value = "/getCheckCode", method = RequestMethod.POST)
    public Object getCheckCode(UmsAdmin user){
        System.out.println(user+"传值111111111111111111");
        log.info("进入方法getCheckCode:"+user.toString());
        RestResponse restResponse = new RestResponse();
        String checkCode = String.valueOf(new Random().nextInt(899999) + 100000);
        System.out.println(checkCode+"验证码");
        String message = "您的注册验证码为："+checkCode;
        mailService.sendSimpleMail(user.getEmail(), "注册验证码", message);
        return checkCode;
    }
}
